﻿Imports Entities
Imports Business
Imports DataAccess
Public Class ModificarVenta
    Private _VentasList As New List(Of VentaR)
    Private _Venta As New VENTAS
    Private _Boleta As New boletas
    ' Private _Factura As New facturasventa
    Private _Cliente As New CLIENTES
    Private _Calle As New CALLES
    Private _Villa As New VILLAS
    Private _PagosList As New List(Of PagoR)
    Private _Detalles As New List(Of DetalleVentaR)
    Private _ItemList As New List(Of ITEMES)
    Private _GarantiaList As New List(Of GARANTIAS)

    Private Sub ModificarVenta_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        cargarLista()
        If Not IsNothing(_Venta) And _Venta.VENTA > 0 AndAlso Not IsNothing(_Boleta) AndAlso _Boleta.BOLETA > 0 Then
            _PagosList = PagosBL.ListPagosR(_Venta.VENTA)
            _Detalles = VentaBL.GetDetalleR(_Venta.VENTA)

            TituloGrillas()
            CalcularTotales()
        End If
    End Sub

    Private Sub ModificarVenta_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        With cChofer
            .DataSource = ChoferBL.List
            .ValueMember = "RUT"
            .DisplayMember = "NOMBRES"
            .SelectedIndex = -1
        End With
        With cCamion
            .DataSource = CamionBL.List
            .ValueMember = "PATENTE"
            .DisplayMember = "DESCRIPCION"
            .SelectedIndex = -1
        End With
        With cVIllas
            .DataSource = VillaBL.List
            .ValueMember = "Villa"
            .DisplayMember = "Nombre"
            .SelectedIndex = -1
        End With
        cCalles.DataSource = Nothing
        bNuevoDetalle.Enabled = False
        bAnular.Enabled = False
        bModificar.Enabled = False

    End Sub

#Region "Metodos Privados"

    Private Sub cargarLista()
        _VentasList = VentaBL.ListByFechas(tFiltro.Value.ToShortDateString, tFiltro.Value.ToShortDateString)
        Titulo()
    End Sub

    Private Sub Limpiar()
        cChofer.SelectedIndex = -1
        cCamion.SelectedIndex = -1
        cCalles.SelectedIndex = -1
        cVIllas.SelectedIndex = -1

        tNumero.Clear()
        tFecha.Value = Now
        tHora.Value = Now
        tKilos.Clear()
        tMontoPagado.Clear()
        tMontoTotal.Clear()
        tPendiente.Clear()
        tSubtotal.Clear()
        tDscto.Clear()
        tDesctoPOS.Text = FormatCurrency(0)
        tNPedido.Clear()
        oPedidoPOS.Checked = False
        _Venta = New VENTAS
        _Cliente = New CLIENTES
        _PagosList = New List(Of PagoR)
        _Detalles = New List(Of DetalleVentaR)
        _ItemList = (New List(Of ITEMES))
        _GarantiaList = New List(Of GARANTIAS)

        TituloGrillas()
        'cargarLista()
        bAnular.Enabled = False
        bModificar.Enabled = False
        bNuevoDetalle.Enabled = False
        'cargarLista()
    End Sub
    Private Sub CalcularTotales()
        Dim total, pagado, kilos As Long
        For Each det In _Detalles
            total += det.Valor * det.Cantidad
            If det.ItemId > 0 Then kilos += det.Cantidad * ItemBL.GetKilos(det.ItemId)
        Next
        If Not IsNothing(_PagosList) Then
            For Each pago In _PagosList
                pagado += pago.Monto
            Next
        Else
            pagado = 0
        End If


        tSubtotal.Text = FormatCurrency(total)
        tKilos.Text = kilos
        tMontoPagado.Text = FormatCurrency(pagado)
        tMontoTotal.Text = FormatCurrency(total - FormatNumber(tDscto.Text) - FormatNumber(tDesctoPOS.Text))
        tPendiente.Text = FormatCurrency(FormatNumber(tMontoTotal.Text) - pagado)

    End Sub

    Private Sub Titulo()
        If IsNothing(_VentasList) Then
            Util.Mensaje("No Existen Ventas en el día Seleccionado")
            gVentas.DataSource = Nothing
            Limpiar()
            Exit Sub
        End If

        With gVentas
            .DataSource = _VentasList
            .Columns("ventaId").Visible = False
            .Columns("FormaPago").Visible = False
        End With
        TituloGrillas()
    End Sub

    Private Sub TituloGrillas()
        Dim bCell As New DataGridViewButtonCell
        Dim colEdit As New DataGridViewButtonColumn With {.CellTemplate = bCell, .Name = "colEdit", .HeaderText = "Editar"}
        Dim colDel As New DataGridViewButtonColumn With {.CellTemplate = bCell, .Name = "colDel", .HeaderText = "Eliminar"}
        Dim colDel2 As New DataGridViewButtonColumn With {.CellTemplate = bCell, .Name = "colDel2", .HeaderText = "Eliminar"}


        With gPagos
            .DataSource = _PagosList

            .Font = New Drawing.Font("Tahoma", Util.GridFont, FontStyle.Regular, GraphicsUnit.Point)
            If Not .Columns.Contains("colEdit") Then
                .Columns.Add(colEdit)
            End If
            If Not .Columns.Contains("colDel") Then
                .Columns.Add(colDel)
            End If
            If (Not IsNothing(_PagosList)) Then
                .Columns("pagoid").Visible = False
                .Columns("tipo").Visible = False
                .Columns("hora").Visible = False

                .Columns("formapagoid").Visible = False
                .Columns("monto").DefaultCellStyle.Format = "$ ###,###,##0"
                '.Columns("formapago").HeaderText = "Forma de Pago"
                .Columns("colEdit").DisplayIndex = 6
                .Columns("colDel").DisplayIndex = 7
            Else
                If .Columns.Contains("colEdit") Then
                    .Columns.Remove("colEdit")
                End If
                If .Columns.Contains("colDel") Then
                    .Columns.Remove("colDel")
                End If
            End If
            For Each col As DataGridViewColumn In .Columns
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                col.ReadOnly = True
            Next
        End With
        With gDetalle
            .DataSource = Nothing
            .DataSource = _Detalles
            .Font = New Drawing.Font("Tahoma", Util.GridFont, FontStyle.Regular, GraphicsUnit.Point)
            If Not .Columns.Contains("colDel2") Then
                .Columns.Add(colDel2)
            End If
            If Not IsNothing(_Detalles) Then
                .Columns("valor").DefaultCellStyle.Format = "$ ###,###,##0"
                '.Columns("precioventa").DefaultCellStyle.Format = "$ ###,###,##0"
                .Columns("itemid").Visible = False
                .Columns("garantiaid").Visible = False
                .Columns("colDel2").DisplayIndex = 5
            Else
                If .Columns.Contains("colDel2") Then
                    .Columns.Remove("colDel2")
                End If
            End If
            For Each col As DataGridViewColumn In .Columns
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
                col.ReadOnly = True
            Next
        End With

    End Sub

#End Region
    

    Private Sub tFiltro_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tFiltro.ValueChanged
        If tFecha.Value.ToShortDateString > Now.ToShortDateString Then
            Util.Mensaje("No Puede Seleccionar una Fecha Mayor a la Actual")
            tFecha.Value = Now.ToShortDateString
        Else
            cargarLista()
        End If
    End Sub

    Private Sub gVentas_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gVentas.DoubleClick
        Dim hti As System.Windows.Forms.DataGridView.HitTestInfo
        hti = gDetalle.HitTest(e.X, e.Y)
        If hti.Type = DataGridViewHitTestType.ColumnHeader Then
            Exit Sub
        End If

        If gVentas.Rows.IndexOf(gVentas.CurrentRow) >= 0 Then
            _Venta = VentaBL.SearchById(gVentas.Item("ventaId", gVentas.CurrentRow.Index).Value)
            _Cliente = ClienteBL.SearchById(_Venta.CLIENTE)
            _Calle = CalleBL.SearchById(_Cliente.CALLE)

            If _Venta.BOLETA > 0 Then
                _Boleta = BoletaBL.SearchById(_Venta.BOLETA)

            End If

            With _Venta
                cCamion.SelectedValue = .PATENTE
                cChofer.SelectedValue = .RUT
                cVIllas.SelectedValue = _Calle.VILLA
                cCalles.SelectedValue = _Calle.CALLE
                tFecha.Value = CDate(.FECHA)
                tHora.Value = tFecha.Value
                tKilos.Text = .KILOS
                tSubtotal.Text = FormatCurrency(.SUBTOTAL)
                tDscto.Text = FormatCurrency(.DESCTO)
                If Not IsNothing(_Venta.PENDIENTE) Then tPendiente.Text = FormatCurrency(_Venta.PENDIENTE)
                If _Venta.PEDIDOPOSID > 0 Then
                    oPedidoPOS.Checked = True
                    tNPedido.Text = FormatNumber(_Venta.PEDIDOPOSID)
                    tDesctoPOS.Text = FormatCurrency(_Venta.DESCTOPOS)
                End If
            End With

            tNumero.Text = _Cliente.NUMERO

            tMontoTotal.Text = gVentas.Item("total", gVentas.CurrentRow.Index).Value
            tMontoPagado.Text = gVentas.Item("pagado", gVentas.CurrentRow.Index).Value
            bAnular.Enabled = True
            bModificar.Enabled = True
            bNuevoDetalle.Enabled = True
            'PAGOS 
            _PagosList = PagosBL.ListPagosR(_Venta.VENTA)


            'DETALLEventa
            _Detalles = VentaBL.GetDetalleR(_Venta.VENTA)
            TituloGrillas()
            CalcularTotales()
        End If
    End Sub

    Private Sub gDetalle_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gDetalle.Click
        Dim hti As System.Windows.Forms.DataGridView.HitTestInfo
        hti = gDetalle.HitTest(e.X, e.Y)
        If hti.Type = DataGridViewHitTestType.ColumnHeader Then
            Exit Sub
        End If
        If gDetalle.Rows.IndexOf(gDetalle.CurrentRow) > -1 Then
            If gDetalle.CurrentCell.OwningColumn.Name = "colDel2" Then
                If Util.Pregunta("¿Realmente Desea Eliminar el Item de venta?") Then
                    Dim detalle As DetalleVentaR = Nothing
                    If gDetalle.Item("cantidad", gDetalle.CurrentRow.Index).Value = 1 Then
                        'ELIMINAR FILA
                        If gDetalle.Item("itemid", gDetalle.CurrentRow.Index).Value > 0 Then
                            Dim det = _Detalles.Where(Function(f) f.ItemId = gDetalle.Item("itemid", gDetalle.CurrentRow.Index).Value).Single
                            If Not IsNothing(det) Then _Detalles.Remove(det)
                        ElseIf gDetalle.Item("garantiaid", gDetalle.CurrentRow.Index).Value > 0 Then
                            Dim det = _Detalles.Where(Function(f) f.GarantiaId = gDetalle.Item("garantiaid", gDetalle.CurrentRow.Index).Value).Single
                            If Not IsNothing(det) Then _Detalles.Remove(det)
                        End If
                    Else
                        'QUITAR A LA CANTIDAD
                        If gDetalle.Item("itemid", gDetalle.CurrentRow.Index).Value > 0 Then
                            Dim det = _Detalles.Where(Function(f) f.ItemId = gDetalle.Item("itemid", gDetalle.CurrentRow.Index).Value).Single
                            If Not IsNothing(det) Then det.Cantidad -= 1
                        ElseIf gDetalle.Item("garantiaid", gDetalle.CurrentRow.Index).Value > 0 Then
                            Dim det = _Detalles.Where(Function(f) f.GarantiaId = gDetalle.Item("garantiaid", gDetalle.CurrentRow.Index).Value).Single
                            If Not IsNothing(det) Then det.Cantidad -= 1
                        End If

                    End If
                    TituloGrillas()
                    CalcularTotales()
                End If
            End If
            If gDetalle.CurrentCell.OwningColumn.Name = "Valor" Then
                Dim valor As Long
                Using Precio As New IngresoDato("Ingreso de Precio", "Precio de Venta", "$")
                    Precio.ShowDialog()
                    If Precio.DialogResult = DialogResult.OK Then
                        valor = Precio.GetValue
                    End If
                End Using
                If gDetalle.Item("itemid", gDetalle.CurrentRow.Index).Value > 0 Then
                    Dim det = _Detalles.Where(Function(f) f.ItemId = gDetalle.Item("itemid", gDetalle.CurrentRow.Index).Value).Single
                    If Not IsNothing(det) And valor > 0 Then det.Valor = valor
                ElseIf gDetalle.Item("garantiaid", gDetalle.CurrentRow.Index).Value > 0 Then
                    Dim det = _Detalles.Where(Function(f) f.GarantiaId = gDetalle.Item("garantiaid", gDetalle.CurrentRow.Index).Value).Single
                    If Not IsNothing(det) And valor > 0 Then det.Valor = valor
                End If
                TituloGrillas()
                CalcularTotales()
            End If
        End If
    End Sub

    Private Sub gPagos_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gPagos.Click
        Dim hti As System.Windows.Forms.DataGridView.HitTestInfo
        hti = gPagos.HitTest(e.X, e.Y)
        If hti.Type = DataGridViewHitTestType.ColumnHeader Then
            Exit Sub
        End If

        If gPagos.Rows.IndexOf(gPagos.CurrentRow) >= 0 Then
            If gPagos.CurrentCell.OwningColumn.Name = "colEdit" Then
                Using Form As New RecibirPago("Modificar Pago", gPagos.Item("monto", gPagos.CurrentRow.Index).Value, gPagos.Item("formapagoid", gPagos.CurrentRow.Index).Value)
                    Form.ShowDialog()
                    If Form.DialogResult = Windows.Forms.DialogResult.OK Then
                        For Each pag In _PagosList
                            If pag.PagoId = gPagos.Item("pagoid", gPagos.CurrentRow.Index).Value Then
                                pag.Monto = Form.GetValue
                                pag.FormaPagoId = Form.GetFpago
                                pag.FormaPago = FormaPagoBL.GetDescripcion(pag.FormaPagoId)
                            End If
                        Next
                        gPagos.DataSource = New List(Of PagoR)
                        TituloGrillas()
                    End If
                End Using
            End If
            If gPagos.CurrentCell.OwningColumn.Name = "colDel" Then
                If Util.Pregunta("¿Realmente Desea Eliminar el pago?") Then
                    Dim pag As New PagoR
                    For Each pago In _PagosList
                        If pago.PagoId = gPagos.Item("pagoid", gPagos.CurrentRow.Index).Value Then
                            pag = pago
                        End If
                    Next
                    _PagosList.Remove(pag)
                    gPagos.DataSource = New List(Of PagoR)
                    TituloGrillas()
                End If
            End If
            CalcularTotales()

        End If

    End Sub

    Private Sub bAnular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bAnular.Click
        If Util.Pregunta("¿Realmente Desea Anular esta Venta?") Then
            If Not IsNothing(_Venta.VENTA) Then
                If VentaBL.Delete(_Venta.VENTA) Then
                    Util.Mensaje("Venta Anulada Correctamente")
                    Limpiar()
                    cargarLista()
                End If
            End If
        End If
    End Sub

    Private Sub bCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCancelar.Click
        Dispose()
    End Sub

    Private Sub bModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bModificar.Click
        If _Detalles.Count = 0 Then
            Util.Mensaje("Asigne Productos a la Venta")
            Exit Sub
        End If
        If CLng(tPendiente.Text) < 0 Then
            Util.Mensaje("No Puede haber Saldo Pendiente a favor del Cliente, Porfavor Revise el Detalle de la Venta y/o los Pagos")
            Exit Sub
        End If

        If Not IsNothing(_Venta.VENTA) Then
            _Cliente = ClienteBL.SearchByDireccion(tNumero.Text.Trim, cCalles.SelectedValue)
            If IsNothing(_Cliente) Then
                'UPDATE CLIENTE
                _Cliente = New clientes
                _Cliente.NUMERO = tNumero.Text.Trim
                _Cliente.CALLE = cCalles.SelectedValue
                _Cliente.ACTIVO = True
                _Cliente = ClienteBL.Save(_Cliente)
                If IsNothing(_Cliente) Then
                    Exit Sub
                End If
            End If
            'UPDATE VENTA
           
            With _Venta
                .CLIENTE = _Cliente.CLIENTE
                .FECHA = CDate(tFecha.Value.ToShortDateString + " " + tHora.Value.ToShortTimeString)
                .RUT = cChofer.SelectedValue
                .PATENTE = cCamion.SelectedValue
                .PENDIENTE = CLng(tPendiente.Text)
                .KILOS = CLng(tKilos.Text)
                .PRECIOTOTAL = CLng(tMontoTotal.Text)
                .SUBTOTAL = CLng(tSubtotal.Text)
                .DESCTO = CLng(tDscto.Text)
                .BOLETA = _Boleta.BOLETA
                If oPedidoPOS.Checked Then
                    _Venta.PEDIDOPOSID = CLng(tNPedido.Text)
                    _Venta.DESCTOPOS = CLng(tDesctoPOS.Text)
                Else
                    _Venta.PEDIDOPOSID = 0
                    _Venta.DESCTOPOS = 0
                End If
            End With
            _Venta = VentaBL.Update(_Venta)
            If _Venta.BOLETA > 0 Then
                _Boleta = BoletaBL.SearchById(_Venta.BOLETA)
                With _Boleta
                    .TOTAL = _Venta.PRECIOTOTAL
                    .MONTONETO = _Venta.SUBTOTAL
                    .DESCUENTO = _Venta.DESCTO
                    .FECHA = _Venta.FECHA
                End With
                _Boleta = BoletaBL.Save(_Boleta)
            End If

            'If _Venta.FACTURAID > 0 Then
            '    _Factura = FacturaVentaBL.SearchById(_Venta.FACTURAID)
            '    With _Factura

            '        .TOTAL = _Venta.PRECIOTOTAL
            '        .MONTONETO = _Venta.SUBTOTAL
            '        .IVA = _Venta.DESCTO
            '        .FECHAEMISION = _Venta.FECHA
            '    End With
            '    _Factura = FacturaVentaBL.Save(_Factura)

            'End If

            'UPDATE PAGOS
            If Not IsNothing(_PagosList) Then
                PagosBL.UpdatePagos(_Venta.VENTA, _PagosList)
            End If
            'UPDATE DETALLE
            VentaBL.UpdateDetalles(_Venta.VENTA, _Detalles)
        End If
      
        If Not IsNothing(VentaBL.Update(_Venta)) Then

            Util.Mensaje("Venta Modificada Correctamente")
            Limpiar()
            cargarLista()
        End If
    End Sub

    Private Sub cVIllas_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cVIllas.SelectedIndexChanged
        If IsNumeric(cVIllas.SelectedValue) AndAlso cVIllas.SelectedIndex > -1 Then
            With cCalles
                .DataSource = CalleBL.ListByVillaId(cVIllas.SelectedValue)
                .ValueMember = "calle"
                .DisplayMember = "nombre"

            End With
        End If
    End Sub

    Private Sub tNumero_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tNumero.Leave
        If tNumero.TextLength > 0 Then
            _Cliente = ClienteBL.SearchByDireccion(tNumero.Text.Trim, cCalles.SelectedValue)

        End If
    End Sub

    Private Sub bNuevoDetalle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bNuevoDetalle.Click
        Using Form As New AgregarDetalleVenta("Agregar Detalle de Venta")
            Form.ShowDialog()
            If Form.DialogResult = Windows.Forms.DialogResult.OK Then
                Dim det As DetalleVentaR = Form.getDetalle
                If Not IsNothing(det) Then
                    If det.ItemId > 0 Then
                        Dim detalle = _Detalles.Where(Function(f) f.ItemId = det.ItemId).SingleOrDefault
                        If Not IsNothing(detalle) Then
                            detalle.Cantidad += 1
                        Else
                            _Detalles.Add(det)
                        End If
                    End If

                    If det.GarantiaId > 0 Then
                        Dim detalle = _Detalles.Where(Function(f) f.GarantiaId = det.GarantiaId).SingleOrDefault
                        If Not IsNothing(detalle) Then
                            detalle.Cantidad += 1
                        Else
                            _Detalles.Add(det)
                        End If
                    End If

                    TituloGrillas()
                    CalcularTotales()
                End If
            End If
        End Using
    End Sub

    
    Private Sub tDscto_Click(sender As Object, e As EventArgs) Handles tDscto.Click
        If (Not String.IsNullOrEmpty(tDscto.Text)) Then
            tDscto.SelectionStart = 0
            tDscto.SelectionLength = tDscto.Text.Length
        End If
    End Sub

    Private Sub tDscto_Leave(sender As Object, e As EventArgs) Handles tDscto.Leave
        Try
            tDscto.Text = FormatCurrency(tDscto.Text)
            Dim n = CLng(FormatNumber(tDscto.Text))
            CalcularTotales()
        Catch ex As Exception
            tDscto.Text = FormatCurrency(0)
        End Try

    End Sub

#Region "Eventos keyPress"
    Private Sub tNumero_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tNumero.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub cVIllas_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cVIllas.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub cCalles_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cCalles.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub cCamion_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cCamion.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub cChofer_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cChofer.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub tFecha_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tFecha.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub tHora_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tHora.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub

    Private Sub tDscto_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tDscto.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Util.Siguiente()
        End If
    End Sub
#End Region

    Private Sub oPedidoPOS_CheckedChanged(sender As Object, e As EventArgs) Handles oPedidoPOS.CheckedChanged
        If oPedidoPOS.Checked Then
            tNPedido.Visible = True
            lbNPedido.Visible = True
            tDesctoPOS.Visible = True
            lbValor.Visible = True
        Else
            tNPedido.Visible = False
            lbNPedido.Visible = False
            tDesctoPOS.Visible = False
            lbValor.Visible = False
        End If
    End Sub

    Private Sub tDesctoPOS_Leave(sender As Object, e As EventArgs) Handles tDesctoPOS.Leave
        Try
            tDesctoPOS.Text = FormatCurrency(tDesctoPOS.Text)
            Dim n = CLng(FormatNumber(tDesctoPOS.Text))
            CalcularTotales()
        Catch ex As Exception
            tDesctoPOS.Text = FormatCurrency(0)
        End Try

    End Sub

    Private Sub tDesctoPOS_Click(sender As Object, e As EventArgs) Handles tDesctoPOS.Click
        If (Not String.IsNullOrEmpty(tDesctoPOS.Text)) Then
            tDesctoPOS.SelectionStart = 0
            tDesctoPOS.SelectionLength = tDesctoPOS.Text.Length
        End If
    End Sub
End Class